import { createRouter, createWebHashHistory } from 'vue-router'

import AppLogin from '@/components/AppLogin.vue'
import LanchPage from '@/components/LanchPage.vue'
import MenuPage from '@/components/MenuPage.vue'
import HomePage from '@/components/HomePage.vue'
import SetUserLocation from '@/components/SetUserLocation.vue'
import ClubApply from '@/components/ClubApply.vue'
import FeedBack from '@/components/FeedBack.vue'
import ForgetPassword from "@/components/ForgetPassword.vue";
import SearchPage from "@/components/SearchPage.vue";
import UserAgreement from "@/components/UserAgreement.vue";

import MarketPage from '@/components/MarketPages/MarketPage.vue'
import MarketOrder from '@/components/MarketPages/MarketOrder.vue'
import MarketCart from '@/components/MarketPages/MarketCart.vue'
import MarketEvaluate from '@/components/MarketPages/MarketEvaluate.vue'
import AddEvaluate from '@/components/MarketPages/AddEvaluate.vue'
import RefundPage from '@/components/MarketPages/RefundPage.vue'
import RefundDetail from '@/components/MarketPages/RefundDetail.vue'
import GoodsDetail from '@/components/MarketPages/GoodsDetail.vue'

import PersonPage from '@/components/UserInfo/PersonPage.vue'
import PersonDetails from '@/components/UserInfo/PersonDetails.vue'
import Changenickname from "@/components/UserInfo/ChangeNickname.vue";
import ChangeDescription from "@/components/UserInfo/ChangeDescription.vue";
import EditPassword from "@/components/UserInfo/EditPassword.vue";
import ZhujiaoInfo from "@/components/UserInfo/ZhujiaoInfo.vue";
import PersonSettings from "@/components/UserInfo/PersonSettings.vue";
import UserOrder from "@/components/UserInfo/UserOrder.vue";
import UserPage from '@/components/UserInfo/UserPage.vue'
import UserFollowsAndFans from '@/components/UserInfo/UserFollowsAndFans.vue'

import GroundPages from '@/components/GroundPages/GroundPage.vue'
import AddTrend from '@/components/GroundPages/AddTrend.vue'
import TrendsDetail from '@/components/GroundPages/TrendsDetail.vue'

import ClubListPage from '@/components/TableReservation/ClubListPage.vue'
import ClubInfoPage from '@/components/TableReservation/ClubInfoPage.vue'
import TableOpen from '@/components/TableReservation/TableOpen.vue'
import TableReserve from '@/components/TableReservation/TableReserve.vue'
import TablePlaying from '@/components/TableReservation/TablePlaying.vue'
import CheckOut from '@/components/TableReservation/CheckOut.vue'
import DiancanPage from '@/components/TableReservation/DiancanPage.vue'
import TableYuyueing from '@/components/TableReservation/TableYuyueing.vue'
import PaySuccess from '@/components/TableReservation/PaySuccess.vue'
import OrderDetail from '@/components/TableReservation/OrderDetail.vue'

import ZhujiaoApply from '@/components/ZhuJiaoPages/ZhujiaoApply.vue'
import ZhujiaoListPage from '@/components/ZhuJiaoPages/ZhujiaoListPage.vue'
import ZhujiaoDetail from '@/components/ZhuJiaoPages/ZhujiaoDetail.vue'
import ZhujiaoReserve from '@/components/ZhuJiaoPages/ZhujiaoReserve.vue'
import ZhujiaoReward from '@/components/ZhuJiaoPages/ZhujiaoReward.vue'
import ZhujiaoRewardPay from '@/components/ZhuJiaoPages/ZhujiaoRewardPay.vue'

import WSTestPage from '@/components/MessagePages/WSTestPage.vue'
import NoticePage from '@/components/MessagePages/NoticePage.vue'

import JiaoPei from "@/components/TeachPages/JiaoPei.vue";

import MyCollection from '@/components/CollectionPages/MyCollection.vue'

import Competition from "@/components/CompetitionPages/Competition.vue"
import CompetitionDetail from "@/components/CompetitionPages/CompetitionDetail.vue"

import MyWallet from "@/components/MyWallet/MyWallet.vue";
import JiFenSignup from "@/components/MyWallet/JiFenSignup/JiFenSignup.vue";
import JiFenmainPage from "@/components/MyWallet/JiFenMain/mainPage.vue";

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {
            path: '/',
            component: LanchPage,
            meta: { isAuth: false }
        },
        {
            path: '/applogin',
            component: AppLogin,
            meta: { isAuth: false }
        },
        {
            path: '/feedback',
            component: FeedBack,
            meta: { isAuth: false }
        },
        {
            path: '/setuserlocation',
            component: SetUserLocation,
            meta: { isAuth: true }
        },
        {
            path: '/clubapply',
            component: ClubApply,
            meta: { isAuth: true }
        },
        {
            path: '/forgetPassword',
            component: ForgetPassword,
            name: 'ForgetPassword',
            meta: { isAuth: false }
        },
        {
            path: '/searchpage',
            component: SearchPage,
            name: 'SearchPage',
            meta: { isAuth: false }
        },
        {
            path: '/useragreement',
            component: UserAgreement,
            name: 'UserAgreement',
            meta: { isAuth: false }
        },
        {
            path: '/menupage',
            component: MenuPage,
            redirect: '/homepage',
            meta: { isAuth: false },
            children: [
                {
                    path: '/homepage',
                    component: HomePage,
                    meta: { isAuth: false },
                },
                {
                    path: '/groundpage',
                    component: GroundPages,
                },

                {
                    path: '/marketpage',
                    component: MarketPage,
                    meta: { isAuth: false }
                },
                {
                    path: '/personpage',
                    component: PersonPage,
                    meta: { isAuth: true }
                },
            ]
        },

        {
            path: '/marketorder',
            component: MarketOrder,
        },
        {
            path: '/marketcart',
            component: MarketCart,
        },
        {
            path: '/marketevaluate',
            component: MarketEvaluate,
        },
        {
            path: '/addevaluate/:orderinfo',
            component: AddEvaluate,
            name: "AddEvaluate"
        },
        {
            path: '/refundpage',
            component: RefundPage,
            name: "RefundPage"
        },
        {
            path: '/refunddetail/:refundinfo',
            component: RefundDetail,
            name: "RefundDetail"
        },
        {
            path: '/goodsdetail/:goodsinfo',
            component: GoodsDetail,
            name: "GoodsDetail"
        },
        {
            path: '/addtrend',
            component: AddTrend,
        },
        {
            path: '/trendsdetail/:trendinfo',
            component: TrendsDetail,
            name: "TrendsDetail"
        },
        {
            path: '/personsettings',
            component: PersonSettings,
            meta: { isAuth: true }
        },
        {
            path: '/persondetails',
            component: PersonDetails,
            meta: { isAuth: true }
        },
        {
            path: '/zhujiaoinfo',
            component: ZhujiaoInfo,
            name: "ZhujiaoInfo",
            meta: { isAuth: true }
        },
        {
            path: '/changenickname',
            component: Changenickname,
            meta: { isAuth: true }
        },
        {
            path: '/changedescription',
            component: ChangeDescription,
            meta: { isAuth: true }
        },
        {
            path: '/editpassword',
            component: EditPassword,
            meta: { isAuth: true }
        },
        {
            path: '/zhujiaoapply',
            component: ZhujiaoApply,
            meta: { isAuth: true }
        },
        {
            path: '/zhujiaolistpage/:clubinfo',
            component: ZhujiaoListPage,
            name: "ZhujiaoListPage",
            meta: { isAuth: true }
        },
        {
            path: '/zhujiaodetail/:zhujiaoinfo',
            component: ZhujiaoDetail,
            name: 'ZhujiaoDetail',
            meta: { isAuth: true }
        },
        {
            path: '/zhujiaoreserve/:zhujiaoinfo',
            component: ZhujiaoReserve,
            name: 'ZhujiaoReserve',
            meta: { isAuth: true }
        },
        {
            path: '/zhujiaoreward/:zhujiaoinfo',
            component: ZhujiaoReward,
            name: 'ZhujiaoReward',
            meta: { isAuth: true }
        },
        {
            path: '/ZhujiaoRewardPay/:zhujiaoinfo',
            component: ZhujiaoRewardPay,
            name: 'ZhujiaoRewardPay',
            meta: { isAuth: true }
        },
        {
            path: '/userpage/:userinfo',
            component: UserPage,
            name: 'UserPage',
            meta: { isAuth: true }
        },
        {
            path: '/userfollowsandfans',
            component: UserFollowsAndFans,
            name: 'UserFollowsAndFans',
            meta: { isAuth: true }
        },
        {
            path: '/clublistpage',
            component: ClubListPage,
            meta: { isAuth: true }
        },
        {
            path: '/clubinfopage/:clubinfo',
            component: ClubInfoPage,
            name: 'ClubInfoPage',
            meta: { isAuth: true }
        },
        {
            path: '/tableopen/:clubinfo',
            component: TableOpen,
            name: 'TableOpen',
            meta: { isAuth: true }
        },
        {
            path: '/tablereserve/:clubinfo',
            component: TableReserve,
            name: 'TableReserve',
            meta: { isAuth: true }
        },
        {
            path: '/diancan/:orderinfo',
            component: DiancanPage,
            name: 'DiancanPage',
            meta: { isAuth: true }
        },
        {
            path: '/tableplaying',
            component: TablePlaying,
            name: 'TablePlaying',
            meta: { isAuth: true }
        },
        {
            path: '/tableyuyueing',
            component: TableYuyueing,
            name: 'TableYuyueing',
            meta: { isAuth: true }
        },
        {
            path: '/paysuccess/:orderinfo',
            component: PaySuccess,
            name: 'PaySuccess',
            meta: { isAuth: true }
        },
        {
            path: '/orderdetail/:orderinfo',
            component: OrderDetail,
            name: 'OrderDetail',
            meta: { isAuth: true }
        },
        {
            path: '/checkout',
            component: CheckOut,
            name: 'CheckOut',
            meta: { isAuth: true }
        },
        {
            path: '/wstestpage',
            component: WSTestPage,
            name: 'WSTestPage',
            meta: { isAuth: true }
        },
        {
            path: '/noticepage',
            component: NoticePage,
            name: 'NoticePage',
            meta: { isAuth: true }
        },
        {
            path: '/userorder',
            component: UserOrder,
            name: 'UserOrder',
            meta: { isAuth: true }
        },
        {
            path: '/jiaopei',
            component: JiaoPei,
            name: 'Jiaopei',
            meta: { isAuth: true }
        },
        {
            path: '/competition',
            component: Competition,
            name: 'Competition',
            meta: { isAuth: true }
        },
        {
            path: '/competitiondetail/:competitioninfo',
            component: CompetitionDetail,
            name: 'CompetitionDetail',
            meta: { isAuth: true }
        },
        {
            path: '/mycollection',
            component: MyCollection,
            name: 'MyCollection',
            meta: { isAuth: true }
        },
        {
            path: '/mywallet',
            component: MyWallet,
            name: 'MyWallet',
            meta: { isAuth: true }
        },
        {
            path: '/jiFenSignup',
            component: JiFenSignup,
            name: 'JiFenSignup',
            meta: { isAuth: true }
        },
        {
            path: '/jiFenMain',
            component: JiFenmainPage,
            name: 'JiFenmainPage',
            meta: { isAuth: true }
        }
    ],
    scrollBehavior(to, from, savedPosition) {
        return { left: 0, top: 0 }
    }
})


// router.beforeEach((to, from, next) => {
//     // 首先对token进行验证，没有token即为没有登录或登录失效
//     let token = localStorage.getItem('token');
//     let permission = localStorage.getItem('permission')
//     if (token === null || token === '' || token === undefined) {

//         // permission为true的为需要登录才能查看的路由
//         if (permission == to.meta.permission) {
//             next();
//         } else {
//             alert('您没有权限访问此路由');
//             next('/login');
//         }
//     } else {
//         alert('请先登录，登录已失效');
//         next();
//     }
// })


router.beforeEach((to, from, next) => {
    if (to.path == "/homepage") {
        sessionStorage["quit"] = 1;
    } else {
        sessionStorage["quit"] = 0;
    }
    next();
});

export default router